package train48days;
import java.util.*;
    class Position {
        int x;
        int y;
        int level;

        public Position(int x, int y, int level) {
            this.x = x;
            this.y = y;
            this.level = level;
        }
    }


    public class 走迷宫 {
        public static int bfs(char[][] s,int m,int n){
            int[][] direc = {{-1,0},{0,1},{1,0},{0,-1}};
            //迷宫的入口和出口
            Position enter = new Position(0,1,0);
            Position out = new Position(9,8,0);

            //标记走过得数组
            boolean[][] flg = new boolean[m][n];

            //采用广度优先方式进行遍历
            Queue<Position> queue = new LinkedList<>();
            queue.offer(enter);
            while(!queue.isEmpty()){
                Position cur = queue.poll();
                flg[cur.x][cur.y] = true;

                //如果已经到了出口的位置，则直接返回
                if(cur.x == out.x && cur.y == out.y){
                    return cur.level;
                }
                for(int i = 0;i < 4;i++){
                    Position next = new Position(cur.x + direc[i][0],cur.y + direc[i][1],cur.level + 1);
                    //数组下标没有越界，并且该点是合法路径，并且还没有被标记过
                    if(next.x >= 0 && next.x < 10 && next.y >= 0 && next.y < 10 &&
                            s[next.x][next.y] == '.' && !flg[next.x][next.y]){
                        queue.offer(next);
                    }
                }

            }
            return 0;
        }
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            while(sc.hasNext()){
                char[][] map = new char[10][10];
                for(int i = 0;i < 10;i++){
                    String s = sc.next();
                    for(int j = 0;j < 10;j++){
                        map[i][j] = s.charAt(j);
                    }
                }
                System.out.println(bfs(map,10,10));
            }
        }
    }

